<?php
/**
* @version $Id $
* @package Joomla
* @copyright Copyright (C) 2007 VXD-Hosting. All rights reserved.
* @author Craig Smith
**/
 //jimport( 'joomla.plugin.plugin');

if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
//$_MAMBOTS->registerFunction( 'onAfterStart', 'ecjcrequired' );

global $_MAMBOTS, $mainframe;
if (defined( '_JEXEC' )){

$GLOBALS['database'] = $database = JFactory::getDBO();
if( isset($mainframe) && is_object($mainframe)) {
				$url = $mainframe->isAdmin() ? $mainframe->getSiteURL() : JURI::base();
			} else {
				$url = JURI::base();
			}
$mosConfig_live_site = $GLOBALS['mosConfig_live_site']		= substr_replace($url, '', -1, 1);
			$mosConfig_absolute_path = $GLOBALS['mosConfig_absolute_path']	= JPATH_SITE;
			$mosConfig_cachepath = $GLOBALS['mosConfig_cachepath'] = JPATH_BASE.DS.'cache';
		
//$mainframe->registerEvent(  'onAfterStart', 'ecjcrequired'  );
	$option = isset($_REQUEST['option'])?$_REQUEST['option']:'';
	$task = isset($_REQUEST['task'])?$_REQUEST['task']:'';

if (trim(strtolower($option)) == 'com_user' && trim(strtolower($task)) == 'register' )
	{
	$GLOBALS['database'] = $database = JFactory::getDBO();
    $query = "SELECT params"
    . "\n FROM #__plugins"
    . "\n WHERE element = 'ecjc_redirect'"
    . "\n AND folder = 'system'"
    ;
    $database->setQuery( $query );
    $id     = $database->loadResult();
    //$eitemid_arr = explode($id, "=");
    $eitemid_arr = explode("=", $id);
    //print_r($eitemid_arr);
    $eitemid = $eitemid_arr[1];
	
	global $mainframe;
	$url = 
	$mainframe->redirect( "index.php?option=com_oscommerce&osMod=create_account&Itemid=$eitemid");
	
	}
}else{
$_MAMBOTS->registerFunction(  'onAfterStart', 'ecjcrequired'  );
}

//$eitemid 	= $params->get( 'eitemid', 99999 );

function ecjcrequired ()
{
	//$option = mosGetParam($_REQUEST, "option", '');
	//$task	 = mosGetParam($_REQUEST, "task", '');
	$option = isset($_REQUEST['option'])?$_REQUEST['option']:'';
	$task = isset($_REQUEST['task'])?$_REQUEST['task']:'';
	

	
	if( trim(strtolower($option)) == 'com_registration' && trim(strtolower($task)) == 'register' )
	{
		//Should be redirected to ECJC registration page...
			//2008-05-22  -- We need to get the Itemid, so lets see if it is set in the xml doc!
	    global $database;

    $query = "SELECT params"
    . "\n FROM #__mambots"
    . "\n WHERE element = 'ecjc_redirect'"
    . "\n AND folder = 'system'"
    ;
    $database->setQuery( $query );
    $id     = $database->loadResult();
    //$eitemid_arr = explode($id, "=");
    $eitemid_arr = explode("=", $id);
    //print_r($eitemid_arr);
    $eitemid = $eitemid_arr[1];
    //die($eitemid_arr[1]);
	//$eitemid = osbotGetParams(
	//print_R($botParams);
		//die();
	mosRedirect(sefRelToAbs("index.php?option=com_oscommerce&amp;osMod=create_account&amp;Itemid=$eitemid"));		
	}
	


	//j1.5
	
	//?option=com_user&task=register
}

?>